package com.grass.p019lv.novel.activity;

import android.view.View;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.lifecycle.ViewModelProvider;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.dialog.ProgressBarDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.google.android.material.tabs.TabLayout;
import com.grass.p019lv.bean.AnchorDetailsFictionBean;
import com.grass.p019lv.databinding.ActivityAudioAnchorDetailsBinding;
import com.grass.p019lv.novel.fragment.AudioAnchorClassFragment;
import com.grass.p019lv.novel.viewmodel.NovelModel;
import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.grass.lv.novel.activity.AudioAnchorDetailsActivity */
public class AudioAnchorDetailsActivity extends BaseActivity<ActivityAudioAnchorDetailsBinding> {
    String HTTP_TAG = "getFictionClassList";
    MyAdapterTab adapter;
    AnchorDetailsFictionBean anchorData;
    int anchorId;
    int classifyIdEd;
    List<LazyFragment> fragmentList;
    private ProgressBarDialog loading;
    NovelModel novelModel;
    List<AnchorDetailsFictionBean.ClassListBean> strings;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_audio_anchor_details;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityAudioAnchorDetailsBinding) this.binding).toolbar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        this.novelModel = (NovelModel) new ViewModelProvider(this).get(NovelModel.class);
        ((ActivityAudioAnchorDetailsBinding) this.binding).setClick(new OnClicks());
        ProgressBarDialog progressBarDialog = new ProgressBarDialog(getActivity());
        this.loading = progressBarDialog;
        progressBarDialog.setHint("拚命載入中...");
        this.loading.show();
        ((ActivityAudioAnchorDetailsBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.activity.AudioAnchorDetailsActivity.View$OnClickListenerC30521 */

            public void onClick(View view) {
                AudioAnchorDetailsActivity.this.finish();
            }
        });
        getUserInfo();
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        this.anchorId = getIntent().getIntExtra("anchorId", -1);
        if (!NetUtil.isNetworkAvailable()) {
            ToastUtils.getInstance().showWeak("網路異常");
            return;
        }
        HttpUtils.getInsatance().get(UrlManager.getInsatance().getFictionAnchorDetail(this.anchorId), new HttpCallback<BaseRes<AnchorDetailsFictionBean>>(this.HTTP_TAG) {
            /* class com.grass.p019lv.novel.activity.AudioAnchorDetailsActivity.C30532 */

            public void onLvSuccess(BaseRes<AnchorDetailsFictionBean> baseRes) {
                if (baseRes.getData() != null) {
                    AudioAnchorDetailsActivity.this.anchorData = baseRes.getData();
                    ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).mo25606c(SpUtils.getInstance().getString("domain") + AudioAnchorDetailsActivity.this.anchorData.getAnchorLogo());
                    TextView textView = ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvTitle;
                    textView.setText(AudioAnchorDetailsActivity.this.anchorData.getAnchorName() + "");
                    TextView textView2 = ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvAttentionNum;
                    textView2.setText(UiUtils.num2str(AudioAnchorDetailsActivity.this.anchorData.getAttentionNum()) + "人关注");
                    TextView textView3 = ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvListenNum;
                    textView3.setText(UiUtils.num2str(AudioAnchorDetailsActivity.this.anchorData.getFakeWatchTimes()) + "人收听");
                    if (AudioAnchorDetailsActivity.this.anchorData.isAttention()) {
                        ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvAttention.setText("已关注");
                    } else {
                        ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvAttention.setText("关注");
                    }
                    if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                        ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).ivBgOpenVip.setVisibility(0);
                    } else {
                        ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).ivBgOpenVip.setVisibility(8);
                    }
                    if (baseRes.getData().getClassList() != null && baseRes.getData().getClassList().size() > 0) {
                        AudioAnchorDetailsActivity.this.setViewPager(baseRes.getData().getClassList(), baseRes.getData().getAnchorId());
                    }
                } else {
                    ToastUtils.getInstance().showWeak("網路異常,請稍後再試");
                }
                if (AudioAnchorDetailsActivity.this.loading != null && AudioAnchorDetailsActivity.this.loading.isShowing()) {
                    AudioAnchorDetailsActivity.this.loading.dismiss();
                }
            }
        });
    }

    /* access modifiers changed from: package-private */
    public void setViewPager(List<AnchorDetailsFictionBean.ClassListBean> list, int i) {
        this.fragmentList = new ArrayList();
        this.strings = list;
        for (int i2 = 0; i2 < this.strings.size(); i2++) {
            AnchorDetailsFictionBean.ClassListBean classListBean = this.strings.get(i2);
            this.fragmentList.add(AudioAnchorClassFragment.newInstance(classListBean.getClassId(), i));
            if (i2 == 0) {
                this.classifyIdEd = classListBean.getClassId();
            }
        }
        this.adapter = new MyAdapterTab(this.fragmentList, this.strings, getSupportFragmentManager(), 1);
        ((ActivityAudioAnchorDetailsBinding) this.binding).viewPager.setAdapter(this.adapter);
        ((ActivityAudioAnchorDetailsBinding) this.binding).viewPager.setOffscreenPageLimit(list.size());
        ((ActivityAudioAnchorDetailsBinding) this.binding).tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) new TabLayout.OnTabSelectedListener() {
            /* class com.grass.p019lv.novel.activity.AudioAnchorDetailsActivity.C30543 */

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabReselected(TabLayout.Tab tab) {
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabSelected(TabLayout.Tab tab) {
                AudioAnchorDetailsActivity.this.changeTabTextView(tab, true);
                AudioAnchorDetailsActivity audioAnchorDetailsActivity = AudioAnchorDetailsActivity.this;
                audioAnchorDetailsActivity.classifyIdEd = audioAnchorDetailsActivity.strings.get(tab.getPosition()).getClassId();
            }

            @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
            public void onTabUnselected(TabLayout.Tab tab) {
                AudioAnchorDetailsActivity.this.changeTabTextView(tab, false);
            }
        });
        ((ActivityAudioAnchorDetailsBinding) this.binding).tabLayout.setupWithViewPager(((ActivityAudioAnchorDetailsBinding) this.binding).viewPager);
        if (((ActivityAudioAnchorDetailsBinding) this.binding).tabLayout.getTabCount() >= 2) {
            for (int i3 = 1; i3 < ((ActivityAudioAnchorDetailsBinding) this.binding).tabLayout.getTabCount(); i3++) {
                changeTabTextView(((ActivityAudioAnchorDetailsBinding) this.binding).tabLayout.getTabAt(i3), false);
            }
        }
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.activity.AudioAnchorDetailsActivity.C30554 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    public void changeTabTextView(TabLayout.Tab tab, boolean z) {
        if (tab.getCustomView() == null) {
            tab.setCustomView(R.layout.tab_layout_text_invention);
        }
        TextView textView = (TextView) tab.getCustomView().findViewById(16908308);
        if (z) {
            textView.setPadding(0, 0, 0, UiUtils.dp2px(12));
            textView.setTextAppearance(this, R.style.TabLayoutAttentionTextSize);
            return;
        }
        textView.setPadding(0, 0, 0, UiUtils.dp2px(12));
        textView.setTextAppearance(this, R.style.TabLayoutNormalAttentionTextSize);
    }

    /* renamed from: com.grass.lv.novel.activity.AudioAnchorDetailsActivity$MyAdapterTab */
    public class MyAdapterTab extends FragmentStatePagerAdapter {
        List<LazyFragment> fragmentList;
        List<AnchorDetailsFictionBean.ClassListBean> titleList;

        public MyAdapterTab(List<LazyFragment> list, List<AnchorDetailsFictionBean.ClassListBean> list2, FragmentManager fragmentManager, int i) {
            super(fragmentManager, i);
            this.fragmentList = list;
            this.titleList = list2;
        }

        @Override // androidx.fragment.app.FragmentStatePagerAdapter
        public Fragment getItem(int i) {
            return this.fragmentList.get(i);
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public int getCount() {
            return this.fragmentList.size();
        }

        @Override // androidx.viewpager.widget.PagerAdapter
        public CharSequence getPageTitle(int i) {
            return this.titleList.get(i).getTitle();
        }
    }

    /* renamed from: com.grass.lv.novel.activity.AudioAnchorDetailsActivity$OnClicks */
    public class OnClicks {
        public OnClicks() {
        }

        public void btnAttention() {
            if (!AudioAnchorDetailsActivity.this.isOnClick()) {
                AudioAnchorDetailsActivity.this.novelModel.attentionAnChorNovel(AudioAnchorDetailsActivity.this.anchorId, !AudioAnchorDetailsActivity.this.anchorData.isAttention());
                AudioAnchorDetailsActivity.this.anchorData.setAttention(!AudioAnchorDetailsActivity.this.anchorData.isAttention());
                if (AudioAnchorDetailsActivity.this.anchorData.isAttention()) {
                    ToastUtils.getInstance().showCorrect("关注成功");
                    ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvAttention.setText("已关注");
                    return;
                }
                ToastUtils.getInstance().showCorrect("取消成功");
                ((ActivityAudioAnchorDetailsBinding) AudioAnchorDetailsActivity.this.binding).tvAttention.setText("关注");
            }
        }

        public void btnBuyVip() {
            if (!AudioAnchorDetailsActivity.this.isOnClick()) {
                ARouter.getInstance().build(Constance.VIP_CENTER_ACTIVITY).withInt("type", 0).navigation();
            }
        }
    }
}
